#ifndef THINK_THINK_CONSOLE_COMMAND_OPTIMIZE_ROUTE_H
#define THINK_THINK_CONSOLE_COMMAND_OPTIMIZE_ROUTE_H

static char* think_console_command_optimize_route =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"namespace think\\console\\command\\optimize;\n"
	"\n"
	"use think\\console\\Command;\n"
	"use think\\console\\Input;\n"
	"use think\\console\\Output;\n"
	"\n"
	"class Route extends Command\n"
	"{\n"
	"    /** @var  Output */\n"
	"    protected $output;\n"
	"\n"
	"    protected function configure()\n"
	"    {\n"
	"        $this->setName(\'optimize:route\')\n"
	"            ->setDescription(\'Build route cache.\');\n"
	"    }\n"
	"\n"
	"    protected function execute(Input $input, Output $output)\n"
	"    {\n"
	"\n"
	"        if (!is_dir(RUNTIME_PATH)) {\n"
	"            @mkdir(RUNTIME_PATH, 0755, true);\n"
	"        }\n"
	"\n"
	"        file_put_contents(RUNTIME_PATH . \'route.php\', $this->buildRouteCache());\n"
	"        $output->writeln(\'<info>Succeed!</info>\');\n"
	"    }\n"
	"\n"
	"    protected function buildRouteCache()\n"
	"    {\n"
	"        $files = \\think\\Config::get(\'route_config_file\');\n"
	"        foreach ($files as $file) {\n"
	"            if (is_file(CONF_PATH . $file . CONF_EXT)) {\n"
	"                $config = include CONF_PATH . $file . CONF_EXT;\n"
	"                if (is_array($config)) {\n"
	"                    \\think\\Route::import($config);\n"
	"                }\n"
	"            }\n"
	"        }\n"
	"        $rules = \\think\\Route::rules(true);\n"
	"        array_walk_recursive($rules, [$this, \'buildClosure\']);\n"
	"        $content = \'<?php \' . PHP_EOL . \'return \';\n"
	"        $content .= var_export($rules, true) . \';\';\n"
	"        $content = str_replace([\'\\\'[__start__\', \'__end__]\\\'\'], \'\', stripcslashes($content));\n"
	"        return $content;\n"
	"    }\n"
	"\n"
	"    protected function buildClosure(&$value)\n"
	"    {\n"
	"        if ($value instanceof \\Closure) {\n"
	"            $reflection = new \\ReflectionFunction($value);\n"
	"            $startLine  = $reflection->getStartLine();\n"
	"            $endLine    = $reflection->getEndLine();\n"
	"            $file       = $reflection->getFileName();\n"
	"            $item       = file($file);\n"
	"            $content    = \'\';\n"
	"            for ($i = $startLine - 1; $i <= $endLine - 1; $i++) {\n"
	"                $content .= $item[$i];\n"
	"            }\n"
	"            $start = strpos($content, \'function\');\n"
	"            $end   = strrpos($content, \'}\');\n"
	"            $value = \'[__start__\' . substr($content, $start, $end - $start + 1) . \'__end__]\';\n"
	"        }\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif